package com.atguigu02.singleton;

/**
 * ClassName: PersonTest
 * Description:
 *   饿汉式
 * @Author liu
 * @Create 2024/11/1 11:23
 * @Version 1.0
 */
public class BankTest {
    public static void main(String[] args) {
        Bank bank1 = Bank.getInstance();
        Bank bank2 = Bank.getInstance();

        System.out.println(bank1 == bank2);
    }

}


/**
 * 饿汉式
 */

class Bank{

    //1.类的构造器的私有化
    private Bank(){

    }

    //2.在类的内部创建当前类的实例
    private static Bank instance = new Bank();

    //3.使用getXxx()方法获取当前类的实例，必须声明为static的
    public static Bank getInstance(){
        return instance;
    }
}